package cn.zniot.so.zniotcore;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

/**
 * 盒子终端协议工厂类
 */
public class ZniotCodecFactory implements ProtocolCodecFactory {

	private ProtocolDecoder decoder;

	private ProtocolEncoder encoder;
	
	/**
	 * 实例化编解码类
	 */
	public ZniotCodecFactory() {
		this.decoder = new ZniotDecoder();
		this.encoder = new ZniotEncoder();
	}
	
	/* @覆盖父类或实现接口的getDecoder（IoSession session）方法
	 * 方法名：getDecoder(IoSession session)
	 * 功　能：返回一个新的(或可重用)的实例，将编码消息对象转换成二进制或特定于协议的数据
	 * 参　数：IoSession session - &盒子跟服务器之间建立的连接会话
	 * 返回值：ProtocolDecoder - &协议编码器
	 * 参　考：@see org.apache.mina.filter.codec.ProtocolCodecFactory#getDecoder(org.apache.mina.core.session.IoSession)
	 */
	@Override
	public ProtocolDecoder getDecoder(IoSession session) throws Exception {
		return this.decoder;
	}

	@Override
	public ProtocolEncoder getEncoder(IoSession session) throws Exception {
		return this.encoder;
	}

}
